package com.xydtech.ecard.ftp.controller;

import com.xydtech.common.annotation.Log;
import com.xydtech.common.core.controller.BaseController;
import com.xydtech.common.core.domain.AjaxResult;
import com.xydtech.common.core.page.TableDataInfo;
import com.xydtech.common.core.text.Convert;
import com.xydtech.common.enums.BusinessType;
import com.xydtech.common.utils.poi.ExcelUtil;
import com.xydtech.ecard.ftp.domain.FtpDepositLoanAdjustmentConfig;
import com.xydtech.ecard.ftp.service.IFtpDepositLoanAdjustmentConfigService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: liliya
 * @Description: ftp_deposit_loan_adjustment_config FTP内生性调整型参数配置表
 * @Date: Created in 2023/8/18 10:11
 * @Modified:
 */
@Controller
@RequestMapping("/ecard/ftp/adjustment/config")
public class FtpDepositLoanAdjustmentConfigController extends BaseController {

    private IFtpDepositLoanAdjustmentConfigService ftpDepositLoanAdjustmentConfigService;
    public FtpDepositLoanAdjustmentConfigController(IFtpDepositLoanAdjustmentConfigService ftpDepositLoanAdjustmentConfigService) {
        this.ftpDepositLoanAdjustmentConfigService = ftpDepositLoanAdjustmentConfigService;
    }

    private String prefix = "ecard/ftp/adjustment";

    @RequiresPermissions("ftpAdjustment:info:view")
    @GetMapping()
    public String redirect()
    {
        return prefix + "/depositLoanAdjustmentConfig";
    }

    /**
     * 查询FTP内生性调整型参数配置表列表
     */
    @RequiresPermissions("ftpAdjustment:info:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(FtpDepositLoanAdjustmentConfig config){
        startPage();
        //TODO 参数暂时不用
        List<FtpDepositLoanAdjustmentConfig> list = ftpDepositLoanAdjustmentConfigService.selectBaseList(config);
        return getDataTable(list);
    }


    /**
     * 导出
     */
    @RequiresPermissions("ftpAdjustment:info:export")
    @Log(title = "FTP内生性调整型参数", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(FtpDepositLoanAdjustmentConfig config){
        //TODO 参数暂时不用
        List<FtpDepositLoanAdjustmentConfig> list = ftpDepositLoanAdjustmentConfigService.selectBaseList(config);
        ExcelUtil<FtpDepositLoanAdjustmentConfig> util = new ExcelUtil<>(FtpDepositLoanAdjustmentConfig.class);
        return util.exportExcel(list, "FTP内生性调整型参数");
    }

    /**
     * 新增跳转
     * @return
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存
     */
    @RequiresPermissions("ftpAdjustment:info:add")
    @Log(title = "参数管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(@Validated FtpDepositLoanAdjustmentConfig config)
    {
        config.setCreateBy(getLoginName());
        config.setUpdateBy(getLoginName());
        return toAjax(ftpDepositLoanAdjustmentConfigService.insertBase(config));
    }

    /**
     * 修改跳转
     */
    @GetMapping("/edit/{configId}")
    public String edit(@PathVariable("configId") Integer configId, ModelMap mmap){
        mmap.put("ftpDepositLoanAdjustmentConfig", ftpDepositLoanAdjustmentConfigService.selectBaseById(configId));
        return prefix + "/edit";
    }

    /**
     * 修改
     */
    @RequiresPermissions("ftpAdjustment:info:edit")
    @Log(title = "参数管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(@Validated FtpDepositLoanAdjustmentConfig config){
        config.setUpdateBy(getLoginName());
        return toAjax(ftpDepositLoanAdjustmentConfigService.updateBase(config));
    }

    /**
     * 删除
     */
    @RequiresPermissions("ftpAdjustment:info:remove")
    @Log(title = "参数管理", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids){
        Long[] configIds = Convert.toLongArray(ids);
        ftpDepositLoanAdjustmentConfigService.deleteBaseByIds(configIds);
        return success();
    }

    public IFtpDepositLoanAdjustmentConfigService getFtpDepositLoanAdjustmentConfigService() {
        return ftpDepositLoanAdjustmentConfigService;
    }

    public void setFtpDepositLoanAdjustmentConfigService(IFtpDepositLoanAdjustmentConfigService
                                                                 ftpDepositLoanAdjustmentConfigService) {
        this.ftpDepositLoanAdjustmentConfigService = ftpDepositLoanAdjustmentConfigService;
    }
}
